#include <iostream>
#include <algorithm>

using namespace std;

const int N = 20010;

int n, m;
int f[N];

int main() {
    cin >> m >> n;
    
    while (n -- ) {
        int v;
        cin >> v;
        for (int j = m; j >= v; -- j) f[j] = max(f[j], f[j - v] + v);
    }
    
    cout << m - f[m] << endl;
    
    return 0;
}